A tour of swing

Simple Swing Application:

 

Swing programs differ from both the console-based programs and the AWT-based programs.Swing programs also have special requirements that relate to threading. The best way to understand the structure of a Swing program is to work through an example. There are two types of Java programs in which Swing is typically used. The first is a desktop application. The second is the applet. This section shows how to create a Swing application. The creation of a Swing applet is described here. Although quite short, the following program shows one way to write a Swing application. In the process, it demonstrates several key features of Swing.

 

Source code:

 

    • import java.awt.*;
      import javax.swing.*;
      import java.awt.event.*;
    • /*
      <applet code = "sw5" width = 250 height = 200>
      </applet>
      */
    • public class sw5 extends JApplet implements ActionListener
      {
      JButton b1,b2,b3,b4;
      ImageIcon i1;
      JTextField t1;
    • public void init()
      {
      Container cp = getContentPane();
      cp.setLayout(new FlowLayout());
    • t1 = new JTextField(20);
      cp.add(t1);
    • i1 = new ImageIcon("cyan-ball.gif");
      b1 = new JButton(i1);
      b1.addActionListener(this);
      cp.add(b1);

    Next

 

 

a tour of SWING by Mrs.s.sharmila banu & MRs.R.jayabharahti